package com.zh.note.huawei.onehundred.寻找连续区间;

import java.util.Arrays;

/**
 * @Author: zhanghuan
 * @date: 2023/8/31 20:04
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        // Scanner sc = new Scanner(System.in);
        // int n = sc.nextInt();
        // int x = sc.nextInt();
        // sc.nextLine();
        // String input = sc.nextLine();
        int n = 3;
        int x = 7;
        String input = "3 4 7";
        int[] nums = Arrays.stream(input.split(" ")).mapToInt(Integer::parseInt).toArray();

        int[] sum = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i - 1] + nums[i - 1];
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            int index = Arrays.binarySearch(sum, sum[i] + x);
            if (index < 0) {
                index = -(index + 1);
            }
            count += n - index + 1;
        }
        System.out.println(count);

    }
}
